package me.cabbit.digitone.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import me.cabbit.digitone.support.Strings;

/**
 * Menu bar for the {@link MainWindow} window. Calls functions on the main window
 * but solves nothing for itself
 * 
 * @author Arkaid
 *
 */
class MainWindowMenu extends JMenuBar implements ActionListener {
	private static final long serialVersionUID = 4098113356539897778L;

	//------------------------------------------------------------------//
	//--------------------------- properties ---------------------------//
	//------------------------------------------------------------------//

	/** Window this menu belongs to */
	protected MainWindow mainWnd;
	
	//------------------------------------------------------------------//
	//----------------------------- methods ----------------------------//
	//------------------------------------------------------------------//

	/**
	 * Constructor. Builds the menu and sets up listeners
	 * 
	 * @param mainWnd Window this menu belongs to
	 */
	public MainWindowMenu(MainWindow mainWnd) 
	{
		//keep a reference to the main window
		this.mainWnd = mainWnd;

		//shorthand
		Strings str = this.mainWnd.strings;
		
		//build menu
		JMenu menu;
		JMenuItem menuItem;
		
		//File
		menu = new JMenu(str.get("MENU_FILE"));
		this.add(menu);
		
		//File->Save PNG
		menuItem = new JMenuItem(str.get("MENU_FILE_SAVE_PNG"));
		menuItem.setActionCommand("MENU_FILE_SAVE_PNG");
		menuItem.addActionListener(this);
		menu.add(menuItem);
		
		//Separator
		menu.addSeparator();
		
		//File->Exit
		menuItem = new JMenuItem(str.get("MENU_FILE_EXIT"));
		menuItem.setActionCommand("MENU_FILE_EXIT");
		menuItem.addActionListener(this);
		menu.add(menuItem);
		
		//Help
		menu = new JMenu(str.get("MENU_HELP"));
		this.add(menu);

		//Help Contents
		menuItem = new JMenuItem(str.get("MENU_HELP_HELP"));
		menuItem.setActionCommand("MENU_HELP_HELP");
		menuItem.addActionListener(this);
		menu.add(menuItem);
		
		//About
		menuItem = new JMenuItem(str.get("MENU_HELP_ABOUT"));
		menuItem.setActionCommand("MENU_HELP_ABOUT");
		menuItem.addActionListener(this);
		menu.add(menuItem);
	}

	//------------------------------------------------------------------//
	//------------------------- ActionListener -------------------------//
	//------------------------------------------------------------------//

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		//call functions on the main window
		switch (e.getActionCommand()) 
		{
		case "MENU_FILE_SAVE_PNG":	this.mainWnd.onMenuSavePNG(); break;
		case "MENU_FILE_EXIT":		this.mainWnd.onMenuFileExit(); break;
		case "MENU_HELP_HELP":		this.mainWnd.onMenuHelp(); break;
		case "MENU_HELP_ABOUT":		this.mainWnd.onMenuAbout(); break;
		}
	}	
}
